/**
 * @filename:ScanController Apr 3, 2024
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2020 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Date;
import java.util.Map;

import com.wonder.app.domain.Scan;
import com.wonder.app.service.ScanService;
import com.wonder.app.request.ScanRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
/**   
 * 
 * <p>说明： 追溯码API接口层</P>
 * @version: 1.1.0
 * @author: Wonder
 * @time    Apr 3, 2024
 *
 */
@Api(tags = "追溯码")
@RestController
@RequestMapping("/app/Scan")
public class ScanController {
	
	@Autowired
	private ScanService scanService;
	
	@ApiOperation(value = "追溯码列表")
	@RequestMapping(value = "/index", method = RequestMethod.POST)
	public Map<String,Object> index(@RequestBody ScanRequest scanRequest) {
		Page<Scan> page = new Page<Scan>(scanRequest.getPage(), scanRequest.getLimit());
		IPage<Scan> list = scanService.selectList(scanRequest, page);
		
		Map<String,Object> retMap=new HashMap<>();
		retMap.put("data",CommonPage.restPage(list));
		
  
		return AjaxMap.success(retMap);
	}
	
	/**
	 * @explain 修改排序开关
	 * @param   entity
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/updateExt")
	@ApiOperation(value = "修改排序开关", notes = "作者：Wonder")
	public AjaxResult<Scan> updateExt(@RequestBody Scan entity){
		if (null!=entity) {
			boolean rsg = scanService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success("system.updateSuccess");
			  }else {
				  return AjaxResult.failed("system.updateFailed");
			  }
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}
	
	/**
	 * @explain 查看对象明细  
	 * @param   map 对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@PostMapping("/detail")
	@ApiOperation(value = "获取追溯码对象明细", notes = "作者：Wonder")
	public AjaxResult<Scan> detail(@RequestBody Map<String,Object> map){
	    if(map==null) return AjaxResult.failed("system.parameterError");
		Long id=Long.parseLong(map.get("id").toString());		
		Scan scan=scanService.getById(id);
		if (null!=scan ) {	
			 return AjaxResult.success(scan);
		}else {
			 return AjaxResult.failed("system.parameterError");
		}
		
	}


	/**
	 * @explain web追溯码绑定订单号
	 * @param   map 对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@PostMapping("/binding")
	@ApiOperation(value = "获取追溯码对象明细", notes = "作者：Wonder")
	public AjaxResult<?> binding(@RequestBody Map<String,Object> map){
		if(map==null) return AjaxResult.failed("system.parameterError");
		List<Long> idList = (List<Long>) map.get("ids");
		String taskBillNo = map.get("taskBillNo").toString();
		Boolean res =  scanService.binding(idList,taskBillNo);
		return AjaxResult.success(res);
	}

}